set more off
global wd "C:\Users\creto\Desktop\chinese_students_2017"

cd "$wd/Data"

set scheme s1mono

use "$wd\Data\6.AnalysisData\City_Control&Policy97-14_citycode.dta",clear 
gen lngdp = log(gdp)
gen lnpop= log(pop)
gen lnpgdp = lngdp - lnpop
keep citycode ln* year
preserve 
keep if year == 2005
rename ln* ln*_0
drop year
save "$wd\Data\lib\tem.dta",replace  // Temporary folder
restore
keep if year == 2011
merge 1:1 citycode using "$wd\Data\lib\tem.dta" // Temporary folder
keep if _m==3
drop _m
gen dlngdp =  lngdp - lngdp_0
gen dlnpgdp =  lnpgdp - lnpgdp_0
gen dlnpop =  lnpop - lnpop_0
keep citycode *_0 dln*
save "$wd\Data\lib\tem_city.dta",replace  // Temporary folder

use "$wd\Data\1.ChinaData\Gaokao\NCEE0511.dta",clear
gen tem = substr(city,1,2)
replace city = tem + "00" if tem=="11"| tem=="12"| tem=="31"| tem=="50"
drop tem
rename city citycode
destring city,replace
collapse (sum) num* , by(city year)
sort citycode year

gen sh_1= num_first/ num_adm
gen sh_211= num_211/ num_adm
gen sh_985= num_985/ num_adm
keep year citycode sh_*
preserve
keep if year == 2005
drop year
rename sh_* sh_*0
save "$wd\Data\lib\tem.dta",replace // Temporary folder
restore
keep if year == 2011
drop year
merge 1:1 citycode using "$wd\Data\lib\tem.dta" // Temporary folder
keep if _m==3
drop _m

gen dsh_1 = sh_1 - sh_10
gen dsh_211 = sh_211 - sh_2110
gen dsh_985 = sh_985 - sh_9850

merge 1:1 citycode using "$wd\Data\6.AnalysisData\IV1_July2019\gapsexpweighted97.dta"  // NTRGap
*keep if _m==3
drop _m
merge 1:1 citycode using "$wd\Data\lib\tem_city.dta" // Temporary folder
*keep if _m==3
drop _m
gen total_pop =exp(lnpop_0)
gen y =.
gen x =.

tostring citycode,replace
gen region = substr(citycode,1,1)
egen id_r = group(region)

* pntr
reg dsh_1 ntrgap_expweighted, robust
reghdfe dsh_1 ntrgap_expweighted, absorb(id_r) vce(robust)
reg dsh_211 ntrgap_expweighted, robust
reghdfe dsh_211 ntrgap_expweighted, absorb(id_r) vce(robust)
reg dsh_985 ntrgap_expweighted, robust
reghdfe dsh_985 ntrgap_expweighted, absorb(id_r) vce(robust)
* gdp
reg dsh_1 dlngdp, robust
reghdfe dsh_1 dlngdp, absorb(id_r) vce(robust)
reg dsh_211 dlngdp, robust
reghdfe dsh_211 dlngdp, absorb(id_r) vce(robust)
reg dsh_985 dlngdp, robust
reghdfe dsh_985 dlngdp, absorb(id_r) vce(robust)
* pgdp
reg dsh_1 dlnpgdp, robust
reghdfe dsh_1 dlnpgdp, absorb(id_r) vce(robust)
reg dsh_211 dlnpgdp, robust
reghdfe dsh_211 dlnpgdp, absorb(id_r) vce(robust)
reg dsh_985 dlnpgdp, robust
reghdfe dsh_985 dlnpgdp, absorb(id_r) vce(robust)

 
